package com.jboltai.resource.vdb;

import com.alibaba.fastjson.JSONObject;
import com.jboltai.capability.vdb.JBoltVDB;
import com.jboltai.capability.vdb.types.elasticsearch.JBoltElasticSearchVDB;
import com.jboltai.capability.vdb.types.milvus.JBoltMilvusVDB;
import com.jboltai.capability.vdb.types.postgresql.JBoltPostgreSQLVDB;
import com.jboltai.capability.vdb.types.tencent.JBoltTencentVDB;

import java.util.Arrays;
import java.util.List;

/**
 * 向量数据库类型
 */
public class VDBType {

    /**
     * 腾讯向量数据库
     */
    public static final VDBType TENCENT = new VDBType(InnerType.tencent.toString(), "腾讯",JBoltTencentVDB.class, new ConfigItem[]{

    });


    /**
     * milvus向量数据库
     */
    public static final VDBType MILVUS = new VDBType(InnerType.milvus.toString(),"MILVUS", JBoltMilvusVDB.class, new ConfigItem[]{

    });


    public static final VDBType PGVECTOR = new VDBType(InnerType.pgvector.toString(), "pgvector", JBoltPostgreSQLVDB.class, new ConfigItem[]{

    });
    /**
     * milvus向量数据库
     */
    public static final VDBType ZILLIZ = new VDBType(InnerType.zilliz.toString(),"zilliz", JBoltMilvusVDB.class, new ConfigItem[]{

    });
    public static final VDBType ELASTIC_SEARCH = new VDBType(InnerType.elasticsearch.toString(),"elasticsearch", JBoltElasticSearchVDB.class, new ConfigItem[]{

    });

    /**
     * 将枚举转换为所需的列表格式
     *
     * @return
     */
    public static List<JSONObject> list() {
        return Arrays.asList(
                new JSONObject().fluentPut("name", TENCENT.getName()).fluentPut("sn", TENCENT.getSn()),
                new JSONObject().fluentPut("name", MILVUS.getName()).fluentPut("sn", MILVUS.getSn()),
                new JSONObject().fluentPut("name", ZILLIZ.getName()).fluentPut("sn", ZILLIZ.getSn()),
                new JSONObject().fluentPut("name", PGVECTOR.getName()).fluentPut("sn", PGVECTOR.getSn()),
                new JSONObject().fluentPut("name", ELASTIC_SEARCH.getName()).fluentPut("sn", ELASTIC_SEARCH.getSn())
                );
    }



    public VDBType(String sn, String name, Class<? extends JBoltVDB> vDbClass, ConfigItem[] configItems) {
        if (vDbClass == null) {
            throw new IllegalArgumentException("vDbClass不能为null");
        }
        this.sn = sn;
        this.name = name;
        this.vDbClass = vDbClass;
    }

    private String sn;
    private String name;


    private ConfigItem[] configItems;

    private Class<? extends JBoltVDB> vDbClass;

    public String getSn() {
        return sn;
    }

    public void setSn(String sn) {

        this.sn = sn;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public ConfigItem[] getConfigItems() {
        return configItems;
    }

    public void setConfigItems(ConfigItem[] configItems) {
        this.configItems = configItems;
    }

    public Class<? extends JBoltVDB> getvDbClass() {
        return vDbClass;
    }
    /**
     * 根据sn查找对应的模型类型
     * @param sn
     * @return
     */
    public static VDBType getBySn(String sn) {
        if (sn == null) {
            throw new IllegalArgumentException("VDB sn 不能为 null");
        }
        switch (sn) {
            case "tencent":
                return TENCENT;
            case "zilliz":
                return ZILLIZ;
            case "milvus":
                return MILVUS;
            case "pgvector":
                return PGVECTOR;
            case "elasticsearch":
                return ELASTIC_SEARCH;
            default:
                throw new IllegalArgumentException("未找到匹配的 VDB : " + sn);
        }

    }
    /**
     * 内置支持的类型
     */
    public static enum InnerType {
        /**
         * 腾讯向量数据库
         */
        tencent,

        milvus,
        /**
         * 线上版milvus
         */
        zilliz,

        pgvector,

        elasticsearch;

        public static InnerType get(String name) {
            for (InnerType type : InnerType.values()) {
                if (type.toString().equalsIgnoreCase(name)) {
                    return type;
                }
            }
            return null;
        }


    }


    private static class ConfigItem {


    }


}
